//
//  SXPtabBar.m
//  oc_weibo
//
//  Created by shixinPeng on 16/3/3.
//  Copyright © 2016年 shixinPeng. All rights reserved.
//

#import "SXPtabBar.h"

#define kItemW KSCREEN_WIDTH*0.2
#define kItemH 50
@interface SXPtabBar ()
/**
 *  中间按钮
 */
@property(nonatomic,weak)UIButton *composeButton;
@end

@implementation SXPtabBar

- (instancetype)init
{
    self = [super init];
    if (self) {
        
        //添加中间控件
        [self addcomposeButton];
    }
    return self;
}

-(void)layoutSubviews{
    
    [super layoutSubviews];

    int i = 0;

    //调整按钮的位置
    for(UIView *view in self.subviews){
        //判断是否是tabbar上的item
        if([view isKindOfClass:NSClassFromString(@"UITabBarButton")]) {
            //调整控件位置,让出中天的位置
            view.frame = CGRectMake(i * kItemW, 0,kItemW, kItemH);
            i++;
            if (i==2) {
                i++;
            }
            
        }
        
    }
}

//添加中间按钮
-(void)addcomposeButton{

    //1.初始化
    UIButton *btn = [[UIButton alloc]init];
    
    self.composeButton = btn;
    //2.设置属性
    [btn setBackgroundImage:[UIImage imageNamed:@"tabbar_compose_button"] forState:UIControlStateNormal];
    [btn setBackgroundImage:[UIImage imageNamed:@"tabbar_compose_button_highlighted" ] forState:UIControlStateHighlighted];
    
    [btn setImage:[UIImage imageNamed:@"tabbar_compose_icon_add"] forState:UIControlStateNormal];
    [btn setImage:[UIImage imageNamed:@"tabbar_compose_icon_add_highlighted"] forState:UIControlStateHighlighted];
    
    btn.frame = CGRectMake(2 * kItemW, 0, kItemW, kItemH);
    
    //添加点击事件
    [btn addTarget:self action:@selector(composeButtonClick) forControlEvents:UIControlEventTouchUpInside];
    
    //3.添加到对应的界面中
    [self addSubview:btn];
}
-(void)composeButtonClick{
    
    SXLog(@"中间按钮点击了");
}

@end
